﻿using LPBToolsLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 电子票存档工具
{
    public enum EBills_InIssuType
    {
        红字发票 = 0,
        蓝字发票 = 1,
    }
    public enum EBills_EInvoiceType
    {
        未知发票 = 0,
        电子发票 = 1,
        纸质发票 = 2,
    }
    public enum EBills_GeneralOrSpecialVAT
    {
        未知发票 = 0,
        增值税专用发票 = 1,
        增值税普通发票 = 2,
    }
    public enum EBills_TaxpayerType
    {
        未知纳税人 = 0,
        一般纳税人 = 1,
        小规模纳税人 = 2,
    }

    public class EBillsSQLSerTools
    {
        public static bool createEBill(IFSQLConfig DBServerCFG, string EIid)
        {
            SQLSerHelper tDBSQLSer = new SQLSerHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("insert into ElecBills(EIid) values('{0}')", EIid);
                try
                {
                    return tDBSQLSer.updateValues(sSQL) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        public static bool updateEBill(IFSQLConfig DBServerCFG, string EIid, string FieldName, string sValue)
        {
            SQLSerHelper tDBSQLSer = new SQLSerHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("update ElecBills set {1}='{2}'  where EIid='{0}'", EIid, FieldName, sValue);
                try
                {
                    return tDBSQLSer.updateValues(sSQL) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="DBServerCFG"></param>
        /// <param name="EIid"></param>
        /// <param name="FieldName"></param>
        /// <param name="sValue"></param>
        /// <returns></returns>
        public static bool updateEBillBlob(IFSQLConfig DBServerCFG, string EIid, string FieldName, string sValue)
        {
            SQLSerHelper tDBSQLSer = new SQLSerHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("update ElecBills set {1}=@{1}  where EIid='{0}'", EIid, FieldName);
                try
                {
                    return tDBSQLSer.updateValues(sSQL, FieldName, sValue) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }
    }

    public class EBillsMySqlTools
    {
        public static bool createEBill(IFSQLConfig DBServerCFG, string EIid)
        {
            MySQLHelper tDBSQLSer = new MySQLHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("insert into ElecBills(EIid) values('{0}')", EIid);
                try
                {
                    return tDBSQLSer.updateValues(sSQL) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        public static bool updateEBill(IFSQLConfig DBServerCFG, string EIid, string FieldName, string sValue)
        {
            MySQLHelper tDBSQLSer = new MySQLHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("update ElecBills set {1}='{2}'  where EIid='{0}'", EIid, FieldName, sValue);
                try
                {
                    return tDBSQLSer.updateValues(sSQL) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="DBServerCFG"></param>
        /// <param name="EIid"></param>
        /// <param name="FieldName"></param>
        /// <param name="sValue"></param>
        /// <returns></returns>
        public static bool updateEBillBlob(IFSQLConfig DBServerCFG, string EIid, string FieldName, string sValue)
        {
            MySQLHelper tDBSQLSer = new MySQLHelper(DBServerCFG);
            if (!string.IsNullOrEmpty(EIid))
            {
                string sSQL = string.Format("update ElecBills set {1}=@{1}  where EIid='{0}'", EIid, FieldName);
                try
                {
                    return tDBSQLSer.updateValues(sSQL, FieldName, sValue) > 0;
                }
                catch
                {
                    return false;
                }
            }
            return false;
        }
    }
}
